package com.example.backend.dto;

import com.example.backend.domain.enums.WebSocketMessageType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * WebSocket消息DTO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WebSocketMessageDto {
    
    /**
     * 消息ID
     */
    private String messageId;
    
    /**
     * 消息类型
     */
    private WebSocketMessageType type;
    
    /**
     * 消息标题
     */
    private String title;
    
    /**
     * 消息内容
     */
    private String content;
    
    /**
     * 发送者信息
     */
    private SenderInfo sender;
    
    /**
     * 接收者信息（可选，用于定向推送）
     */
    private ReceiverInfo receiver;
    
    /**
     * 相关实体信息（工单ID、评论ID等）
     */
    private EntityInfo entity;
    
    /**
     * 额外数据
     */
    private Map<String, Object> data;
    
    /**
     * 消息时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime timestamp;
    
    /**
     * 消息优先级（1-5，5最高）
     */
    private Integer priority;
    
    /**
     * 是否需要确认
     */
    private Boolean requiresAck;

    /**
     * 发送者信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SenderInfo {
        private Long userId;
        private String username;
        private String displayName;
        private String avatar;
        private String role;
    }

    /**
     * 接收者信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ReceiverInfo {
        private Long userId;
        private String username;
        private String role;
        private String department;
    }

    /**
     * 实体信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class EntityInfo {
        private String entityType; // ticket, comment, user等
        private Long entityId;
        private String entityTitle;
        private String entityUrl;
    }
}
